com.prosc.supercontainer.plugin
Class SCPluginModel

java.lang.Object
  extended by com.prosc.supercontainer.plugin.SCPluginModel

public class SCPluginModel
extends java.lang.Object

This class is used to allow any Java code to communicate with a SuperContainer server instance. This can be used by server-side processes or swing clients. Some of the methods in this class only work in a swing client (e.g. chooseFile(java.awt.Component, java.io.File, int, java.lang.String) and upload progress bars).

To use the client, you must first call setBaseUrl:

 final SCPluginModel model = new SCPluginModel();
 final String folderPath = "pictures/123";
 final boolean calculateMd5Hash = false;
 //
 model.setBaseUrl("http://myhost/SuperContainer/Files", "username", "password");
 final SCResourceInfo info = model.getResourceInfo(folderPath, calculateMd5Hash);
 final File destination = new File("/tmp/" + info.getFilename());
 System.out.println("About to download " + folderPath + " (" + info.getContentLength() + " bytes) to " + destination );
 final File result = model.download(folderPath, destination, 0, 0, 0, false, true);
 System.out.println("File downloaded to " + result + " successfully");
 


Field Summary
(package private) static byte LICENSE_VERSION
           
 
Constructor Summary
SCPluginModel()
           
 
Method Summary
 java.io.File chooseFile(java.awt.Component nativeFrame, FileChooserOptions options)
          Convenience method to show a file chooser dialog
 boolean clearLocalCache()
          Clears any temporary items from the supercontainer_downloads directory.
 void delete(java.lang.String folderPath)
          Permanently deletes a file from the SuperContainer server
 void deleteLocal(java.io.File localFile)
          Deletes a local file from the filesystem.
 java.io.File download(java.lang.String folderPath, java.io.File destinationFolderArg, java.lang.String fileNameOverride, DownloadParameters parameters, boolean showProgress, boolean autoUnzip, boolean checkIfFileExists, java.awt.Component nativeFrame)
           
(package private)  java.io.File getPathToFolderOnServer(java.lang.String macPath, java.lang.String winPath, java.lang.String folderPath)
          Fetches the stored file's location as a URL pointing to a mounted/mapped file server.
 SCResourceInfo getResourceInfo(java.lang.String folderPath)
          Returns some information about a given folderPath on the server, without any optional metadata.
 SCResourceInfo getResourceInfo(java.lang.String folderPath, MetadataFlags flags)
          Returns some information about a given folderPath on the server, specifying optional MetaDataFlags to be returned by the server.
 java.lang.String getSuperContainerBase()
          Returns the base URL, as passed to the setBaseUrl(java.lang.String, java.lang.String) function.
 java.lang.String getSuperContainerBaseParent()
          Returns the parent of the base URL, without the "Files" part.
 void move(java.lang.String oldFolderPath, java.lang.String newFolderPath)
          Moves a file on the SuperContainer server without downloading it to the local machine.
 void moveLocal(java.io.File sourceFile, java.io.File destinationFile)
          Moves a file locally from one place on server to another local directory.
 SCResourceInfo resourceInfoFromHeaders(java.util.Map headers, java.lang.String path, MetadataFlags flags)
          An alternate means of getting SCResourceInfo if you already have the headers from the server.
 java.util.List scanDirectory(java.io.File dir, boolean recursive)
          Scans a directory and returns a list of files.
 void setBaseUrl(java.lang.String superContainerBase, java.lang.String sessionId)
           
 void setBaseUrl(java.lang.String superContainerBase, java.lang.String username, java.lang.String password)
          Set the base URL for all subsequent plugin calls.
 void setResource(java.lang.String folderPath, java.io.File file, boolean showProgress, java.awt.Component parent)
          Uploads a file or directory to SuperContainer
 void setResource(java.lang.String folderPath, java.lang.String fileName, java.io.InputStream stream, long length, boolean showProgress, java.awt.Component parent, java.util.Map headers)
          Uploads a resource stream to SuperContainer.
 void setZipResource(java.lang.String folderPath, java.lang.String archiveName, java.io.File[] filesOrDirs, boolean showProgress, java.awt.Component parent)
          Uploads a file array to SuperContainer by creating a new zip archive named name and uploading to the indicated folderPath.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LICENSE_VERSION

static final byte LICENSE_VERSION
See Also:
Constant Field Values
Constructor Detail

SCPluginModel

public SCPluginModel()
Method Detail

chooseFile

public java.io.File chooseFile(java.awt.Component nativeFrame,
                               FileChooserOptions options)
Convenience method to show a file chooser dialog

Parameters:
nativeFrame - TODO
options - parameters which alter the behavior of the file chooser dialog
Returns:
the selected file

clearLocalCache

public boolean clearLocalCache()
Clears any temporary items from the supercontainer_downloads directory.

Returns:
If any deletion fails, returns false, otherwise returns true.

delete

public void delete(java.lang.String folderPath)
            throws java.io.IOException,
                   UnlicensedException
Permanently deletes a file from the SuperContainer server

Parameters:
folderPath - the folderPath of the file to delete on the SuperContainer server.
Throws:
java.io.IOException
UnlicensedException

deleteLocal

public void deleteLocal(java.io.File localFile)
                 throws java.io.IOException
Deletes a local file from the filesystem.

Parameters:
localFile - the file to delete.
Throws:
java.io.IOException - if the file is a directory, or cannot be deleted

download

public java.io.File download(java.lang.String folderPath,
                             java.io.File destinationFolderArg,
                             java.lang.String fileNameOverride,
                             DownloadParameters parameters,
                             boolean showProgress,
                             boolean autoUnzip,
                             boolean checkIfFileExists,
                             java.awt.Component nativeFrame)
                      throws java.io.IOException,
                             UnlicensedException
Throws:
java.io.IOException
UnlicensedException

getPathToFolderOnServer

java.io.File getPathToFolderOnServer(java.lang.String macPath,
                                     java.lang.String winPath,
                                     java.lang.String folderPath)
                               throws java.io.IOException
Fetches the stored file's location as a URL pointing to a mounted/mapped file server. Note that this does not download the file from the SuperContainer server; it returns a URL pointing to the file stored directly on the SuperContainer server. This is useful to combine with the "Open URL" script step in Filemaker to allow opening and editing of stored resources.

NOTE: A mounted or mapped filesystem-accessible storage location is required to open referenced file. Otherwise, you should download the file to the local hard drive using SCGetContainer and open it there.

Parameters:
macPath - Mac OS X path to root SuperContainer storage location
winPath - Windows to root SuperContainer storage location
folderPath - The unique identifier for a SuperContainer file
Returns:
URL to the file
Throws:
java.io.IOException

getResourceInfo

public SCResourceInfo getResourceInfo(java.lang.String folderPath)
                               throws java.io.IOException,
                                      UnlicensedException
Returns some information about a given folderPath on the server, without any optional metadata.

Parameters:
folderPath - the folderPath to fetch information about
Returns:
An SCResourceInfo object which contains metadata about the file on the server, or null if there is no resource at the specified folderPath.
Throws:
java.io.IOException
UnlicensedException

getResourceInfo

public SCResourceInfo getResourceInfo(java.lang.String folderPath,
                                      MetadataFlags flags)
                               throws java.io.IOException,
                                      UnlicensedException
Returns some information about a given folderPath on the server, specifying optional MetaDataFlags to be returned by the server.

Parameters:
folderPath - the folderPath to fetch information about
flags - flags indicating additional data to get from the server
Returns:
An SCResourceInfo object which contains metadata about the file on the server, or null if there is no resource at the specified folderPath.
Throws:
java.io.IOException
UnlicensedException

getSuperContainerBase

public java.lang.String getSuperContainerBase()
Returns the base URL, as passed to the setBaseUrl(java.lang.String, java.lang.String) function.

Returns:
e.g. http://localhost:8020/SuperContainer/Files

getSuperContainerBaseParent

public java.lang.String getSuperContainerBaseParent()
Returns the parent of the base URL, without the "Files" part. This is handy for getting RawData urls.

Returns:
e.g. http://localhost:8020/SuperContainer

move

public void move(java.lang.String oldFolderPath,
                 java.lang.String newFolderPath)
          throws java.io.IOException,
                 UnlicensedException
Moves a file on the SuperContainer server without downloading it to the local machine.

Parameters:
oldFolderPath - The previous folderPath
newFolderPath - The new folderPath
Throws:
java.io.IOException
UnlicensedException - when used with incorect registraion info

moveLocal

public void moveLocal(java.io.File sourceFile,
                      java.io.File destinationFile)
               throws java.io.IOException
Moves a file locally from one place on server to another local directory.

Parameters:
sourceFile - Original file
destinationFile - File to move source file to
!!!FUTURE - - NOT IMPLEMENTED - DO NOT USE!!! overwrite Optional defaults to false, if set, user gets error saying that they can't overwrite file
Throws:
java.io.IOException - thrown when attemting to write dir to file or if there was a problem moving the file.

resourceInfoFromHeaders

public SCResourceInfo resourceInfoFromHeaders(java.util.Map headers,
                                              java.lang.String path,
                                              MetadataFlags flags)
An alternate means of getting SCResourceInfo if you already have the headers from the server.

Parameters:
headers - a map of http header names to values
path - the folderPath
flags - optional flags
Returns:
info about the given resource

scanDirectory

public java.util.List scanDirectory(java.io.File dir,
                                    boolean recursive)
Scans a directory and returns a list of files. Hidden files and directories are not scanned. OS X Bundles are not recursed into (this is not entirely reliable).

Parameters:
dir - The local directory to scan
recursive - Whether to recurse into subdirectories
Returns:
a List of Files

setBaseUrl

public void setBaseUrl(java.lang.String superContainerBase,
                       java.lang.String sessionId)
                throws java.io.IOException
Throws:
java.io.IOException

setBaseUrl

public void setBaseUrl(java.lang.String superContainerBase,
                       java.lang.String username,
                       java.lang.String password)
                throws java.io.IOException
Set the base URL for all subsequent plugin calls. Throws an error if the URL is invalid, or there is no supercontainer server running at this location.

Parameters:
superContainerBase - The base URL where the SuperContainer server is located, e.g. http://localhost:8020/SuperContainer/Files
username - optional username
password - optional password
Throws:
InvalidCredentialsException - if the username and password are invalid
java.io.IOException - if there is a communication failure with the server

setResource

public void setResource(java.lang.String folderPath,
                        java.io.File file,
                        boolean showProgress,
                        java.awt.Component parent)
                 throws java.io.IOException,
                        UnlicensedException
Uploads a file or directory to SuperContainer

Parameters:
folderPath - The folderpath for the newly uploaded file on SuperContainer
file - the file to upload
showProgress - whether to display a progress bar during upload
parent - Component to center the progress dialog on (only applicable if showProgress is true)
Throws:
java.io.IOException
UnlicensedException

setResource

public void setResource(java.lang.String folderPath,
                        java.lang.String fileName,
                        java.io.InputStream stream,
                        long length,
                        boolean showProgress,
                        java.awt.Component parent,
                        java.util.Map headers)
                 throws java.io.IOException,
                        UnlicensedException
Uploads a resource stream to SuperContainer.

Parameters:
folderPath - The folderpath for the newly uploaded file on SuperContainer
fileName - The filename to give the newly uploaded file on SuperContainer
stream - Data stream to send to the server
length - Length of the stream
showProgress - Whether to display a progress dialog
parent - Component to center the progress dialog on (only applicable if showProgress is true)
headers - optional headers to include
Throws:
java.io.IOException
UnlicensedException

setZipResource

public void setZipResource(java.lang.String folderPath,
                           java.lang.String archiveName,
                           java.io.File[] filesOrDirs,
                           boolean showProgress,
                           java.awt.Component parent)
                    throws java.io.IOException,
                           UnlicensedException
Uploads a file array to SuperContainer by creating a new zip archive named name and uploading to the indicated folderPath.

Parameters:
folderPath - which path to upload the files to
archiveName - the name of the created zip file
filesOrDirs - the files to upload. These may contain directories.
showProgress - whether to show progress bar
parent - optional parent to center the dialog around
Throws:
java.io.IOException
UnlicensedException